﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BGMove : MonoBehaviour {

    public float speed = 2f;
    public Transform nextBG;

	// Use this for initialization
	void Start ()
    {
		
	}
	
	// Update is called once per frame
	void Update ()
    {
        Move();
	}
    void Move()
    {
        //两个背景图距离为15，当Z为-25时离开屏幕
        if (transform.position.z <= -25)
        {
            transform.position = new Vector3(0, 0, nextBG.transform.position.z + 15);
        }
        transform.position = transform.position + new Vector3(0, 0, -1) * speed*Time.deltaTime;
    }
}
